package com.yhp.task;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.system.comm.util.DateUtils;
import com.system.common.pojo.BisNurseBag;
import com.yhp.service.BisNurseBagService;

@Component
public class BagTask {
	@Autowired
	private BisNurseBagService bagService;
	
	@Scheduled(cron="0/1800 * * * * ? ")
	public void bag(){
		List<BisNurseBag> list = bagService.select();
		for (BisNurseBag bisNurseBag : list) {
			if (DateUtils.compareDate(bisNurseBag.getPutawayTime(),new Date())) {
				//待上架
				bisNurseBag.setStatus("0");
				bagService.updateByPrimaryKey(bisNurseBag);
			}else if (DateUtils.isInDate(new Date(), bisNurseBag.getPutawayTime(), bisNurseBag.getSoldoutTime())) {
				//在售
				bisNurseBag.setStatus("1");
				bagService.updateByPrimaryKey(bisNurseBag);
			}else if (DateUtils.compareDate(new Date(), bisNurseBag.getSoldoutTime())) {
				//下架
				bisNurseBag.setStatus("2");
				bagService.updateByPrimaryKey(bisNurseBag);
			}
		}
	}
}
